<template>
	<view class="container-withdrawal">
		<view class="flex-between" style="height:100rpx;">
			<view class="" style="font-size: 24rpx;color: #232323;font-weight: bold;">
				{{$t('wallet.name32')}}
			</view>
			<view class="" style="font-size: 24rpx;color: #5d5d5d;"
				@tap="$fun.jump(`/pageA/wallet/withdrawList?name=${$t('wallet.name4')}&type=2`)">
				{{$t('wallet.name33')}}
			</view>
		</view>
		<view class="select flex-between" @tap="handleShow">
			<view class="">
				<view class="title">{{withdVal.name || $t('vnode.name8')}}</view>
			</view>
			<view class="">
				<u-icon name="arrow-right" size="22"></u-icon>
			</view>
		</view>
		<view class="cell">
			<view class="title">
				{{$t('wallet.name34')}}
			</view>
			<view class="">
				<u--input :placeholder="$t('wallet.name35')" border="surround" v-model="addr" suffixIcon="scan"
					suffixIconStyle="fontSize:50rpx"></u--input>
			</view>
		</view>
		<view class="cell">
			<view class="title">
				{{$t('wallet.name36')}}
			</view>
			<view class="network flex-between" @tap="isPopup = true">
				<text class="text" v-if="network">{{network}}</text>
				<text class="plh" v-else> {{$t('wallet.name18')}}</text>
				<div><u-icon name="arrow-down-fill" size="20"></u-icon></div>
			</view>
		</view>
		<view class="cell">
			<view class="title">
				{{$t('wallet.name9')}}
			</view>
			<view class="">
				<u--input :placeholder="$t('wallet.name37')" style="background: #fefefe" border="surround"
					v-model="money"></u--input>
			</view>
			<rich-text :nodes="text"></rich-text>
		</view>

		<view class="bottom">
			<!-- <view class="text">1TOPS≈0.23BTCF</view> -->
			<u-button type="primary" :text="$t('user.name48')" shape="circle" @click="confirm"
				throttleTime="2000"></u-button>
		</view>
		<u-action-sheet :actions="list" :title="$t('wallet.name38')" :show="show" :cancelText="$t('vnode.name10')"
			@close="show = false" @select="handleSelect"></u-action-sheet>
		<u-popup :show="isPopup" @close="closePopup" @open="openPopup" mode="bottom" :round="10" closeable>
			<view class="Popup1">
				<view class="" style="padding-left: 30rpx;">{{$t('wallet.name39')}}</view>
				<view class="tips">
					<text style="color: #232323;font-weight: 600;">{{$t('wallet.name31')}}：</text>
					{{$t('wallet.name23')}}
				</view>
				<view class="main">
					<view class="main-item" v-for="(item,index) in networkList" @click="handleNetwork(item)">
						<view class="tit">{{item}}</view>
						<view class="tex">{{$t('wallet.name24')}} 0</view>
						<view class="tex">{{$t('wallet.name25')}}：2m</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPwd: false,
				money: '',
				list: [],
				bankList: [],
				bid: '',
				id: '',
				titleName: '', //标题
				placeholder: '',
				active: "`",
				balance: '==',
				balance1: '==',
				withdrawal_type: 0,
				isChecked: false,
				btnloading: false,
				marthlist: [],
				isPopup: false,
				list1: [],
				show: false,
				network: '',
				addr: '',
				id: '',
				networkList: [],
				withdVal: {},
				text: ''
			}
		},
		// onNavigationBarButtonTap(e) {
		// 	this.$fun.jump(`/pages/user/wallet/walletdetail?id=${this.id}`)
		// },
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: this.$t('wallet.name4')
			})
			this.id = options.id
			this.titleName = options.name
			this.bid = options.bid
			this.getwithdrawal()
		},
		computed: {
			// openExamine() {
			// 	return this.$store.state.openExamine;
			// }
		},
		watch: {
			money(val) {
				if (val) {
					this.money1 = ''
				}
			}
		},
		methods: {
			handleNetwork(val) {
				this.network = val
				this.isPopup = false
			},
			handleShow() {

				this.show = true
			},
			async getwithdrawal() {
				const res = await this.$fun.ajax.post('config/withdrawal')
				this.list = res.data.list
				this.networkList = res.data.network
				this.text = res.data.text
				if (this.id) {
					this.withdVal = this.list.find(i => i.id == this.id)
				}
			},
			closePopup() {
				this.isPopup = false
			},
			openPopup() {

			},
			// 选择提币
			handleSelect(e) {
				this.withdVal = e
			},
			onChange(item, index) {
				// //console.log(e)
				this.active = index;
				this.bid = item.id;
			},
			configBank(e) {
				this.bid = this.bankList[e.index].id
			},
			async confirm() {
				let {
					withdVal,
					money,
					network,
					addr
				} = this;
				let parms = {
					id: withdVal.id,
					money,
					network,
					addr
				}
				if (!money) {
					this.$fun.msg(this.$t('wallet.name37'))
					return
				}
				if (!withdVal.id) {
					this.$fun.msg(this.$t('wallet.name41'))
					return
				}
				if (!network) {
					this.$fun.msg(this.$t('wallet.name42'))
					return
				}
				if (!addr) {
					this.$fun.msg(this.$t('wallet.name43'))
					return
				}
				this.btnloading = true
				await this.$fun.ajax.post('user/withdrawal', {
					...parms
				}).then(res => {
					if (res.code == 1) {
						this.$fun.msg(res.msg)
						this.$fun.jump('', 4, 1200)
					}
				})
			},
			changePwdState() {
				this.showPwd = !this.showPwd;
			}
		},
		onNavigationBarButtonTap(e) {
			const index = e.index;
			// #ifdef APP-PLUS
			const pages = getCurrentPages();
			const page = pages[pages.length - 1];
			const currentWebview = page.$getAppWebview();
			currentWebview.hideTitleNViewButtonRedDot({
				index
			});
			// #endif
			uni.navigateTo({
				url: `./withdrawList?id=${this.id}&name=${this.titleName}`
			})
		}

	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;
	}

	.container-withdrawal {
		height: 100%;
		padding: 0 30rpx;

		.select {
			height: 100rpx;
			background-color: #e9f5ff;
			padding: 0 30rpx;

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #232323;
				line-height: 38rpx;
			}
		}

		.cell {
			margin: 40rpx 0;

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 26rpx;
				color: #232323;
				line-height: 28rpx;
				margin: 20rpx 0;
			}
		}

		.bottom {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			padding: 30rpx;
			text-align: center;

			.text {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #999999;
				line-height: 38rpx;
			}
		}

		.Popup1 {
			height: 800rpx;
			padding-top: 40rpx;

			.tips {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #676767;
				line-height: 28rpx;
				background-color: #f0f0f0;
				padding: 30rpx 60rpx;
			}

			.main {
				padding: 30rpx;

				.main-item {
					height: 140rpx;
					border: 1rpx solid #cecece;
					padding: 10rpx 30rpx;
					margin: 20rpx 0;

					.tit {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 24rpx;
						color: #232323;
						line-height: 38rpx;
					}

					.tex {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						line-height: 34rpx;
					}
				}
			}
		}

		.network {
			height: 74rpx;
			border: 1rpx solid #dadbde;
			border-radius: 10rpx;
			line-height: 70rpx;
			padding: 0 15rpx;

			.plh {
				color: #cecece;
			}

			.text {}
		}
	}
</style>